import pcd from './pcdList';

const pcdList = pcd.pcdList();
const provinceList = pcdList;
// console.log('city', JSON.stringify(provinceList[1].children[0].value));
module.exports = {
  //省--数字转文字
  provinceCText(value){
    let provinceText = '';
    for (var i = 0; i < provinceList.length; i++) {
      if(provinceList[i].value == value){
        provinceText = provinceList[i].label;
      }
    }
    return provinceText;
  },
  //市--数字转文字
  cityCText(value){
    let cityText = '';
    for (var i = 0; i < provinceList.length; i++) {
      let cityList = provinceList[i].children;
      // console.log('cityList', JSON.stringify(cityList));
      for (var j = 0; j < cityList.length; j++) {
        // console.log('cityList', JSON.stringify(cityList[j]));
          if(cityList[j].value == value){
            cityText = cityList[j].label;
          }
      }
    }
    return cityText;
  },
  //区--数字转文字
  districtCText(value){
    let districtText = '';

    for (var i = 0; i < provinceList.length; i++) {
      let cityList = provinceList[i].children;
      // console.log('cityList', JSON.stringify(cityList));
      for (var j = 0; j < cityList.length; j++) {
        let districtList = cityList[j].children;
        // console.log('cityList', JSON.stringify(cityList[j]));
        for (var k = 0; k < districtList.length; k++) {
          if(districtList[k].value == value){
            districtText = districtList[k].label;
          }
        }
      }
    }
    return districtText;
  },


  //省--文字转数字
  provinceCNumber(label){
    let provinceNumber = '';
    for (var i = 0; i < provinceList.length; i++) {
      if(provinceList[i].label == label){
        provinceNumber = provinceList[i].value;
      }
    }
    return provinceNumber;
  },
  //市--文字转数字
  cityCNumber(label){
    let cityNumber = '';
    for (var i = 0; i < provinceList.length; i++) {
      let cityList = provinceList[i].children;
      // console.log('cityList', JSON.stringify(cityList));
      for (var j = 0; j < cityList.length; j++) {
        // console.log('cityList', JSON.stringify(cityList[j]));
          if(cityList[j].label == label){
            cityNumber = cityList[j].value;
          }
      }
    }
    return cityNumber;
  },
  //区--文字转数字
  districtCNumber(cLabel, dLabel){
    let districtNumber = '';
    for (var i = 0; i < provinceList.length; i++) {
      let cityListItem = provinceList[i].children;
      for (var j = 0; j < cityListItem.length; j++) {
          if(cityListItem[j].label == cLabel){
            let districtList = cityListItem[j].children;
              for (var k = 0; k < districtList.length; k++) {
                if(districtList[k].label == dLabel){
                  districtNumber = districtList[k].value
                }
              }
          }
      }

    }
    return districtNumber;
  },

  //pcd--组合
  pcdListConvert(province, city, district){
    let pcdList = [];
    if(province){
      pcdList.push(province)
    }
    if(city){
      pcdList.push(city)
    }
    if(district){
      pcdList.push(district)
    }
    // console.log("pcdListJSON", JSON.stringify(pcdList));
    return pcdList;
  }

}
